package sort.primarySort;

import sort.SortCompare;
import sort.template;

import java.util.Arrays;

public class Shell extends template {
    public static void sort(Comparable[] a) {
        int length = a.length;
        int h = 1;
        while (h < length / 3)
            h = h * 3 + 1;
        while (h >= 1) {
            for (int i = h; i < length; i++)
                for (int j = i; j >= h && less(a[j], a[j - h]); j -= h)
                    exch(a, j, j - h);
            h /= 3;
        }
    }

    public static void main(String[] args) {
        Comparable[] array = SortCompare.getArray(10);
        System.out.println("分类之前:" + Arrays.asList(array));
        sort(array);
        System.out.println("分类之后:" + Arrays.asList(array));
    }
}
